import 'package:flutter/material.dart';
import 'flow_item_widget.dart';
import 'image_filter.dart';

void main() {
  runApp(MaterialApp(
    title: 'Flutter Demo',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      primarySwatch: Colors.blue,
    ),
    home: HomePage(),
  ));
}

class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = new AnimationController(
        vsync: this, duration: Duration(milliseconds: 1000));
    _controller.addListener(() {
      setState(() {});
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("循环滚动的banner"),
      ),
      backgroundColor: Colors.blueGrey,
      body: Stack(children: [
        Positioned(
          left: 60,
          top: 20,
          right: 60,
          height: 60,
          child: ImageFilterWidget(0.5),
        ),
        Positioned(
          left: 20 + 40 * _controller.value,
          top: 120 - 100 * _controller.value,
          right: 20 + 40 * _controller.value,
          height: 70 - 10 * _controller.value,
          child: ImageFilterWidget(0.0),
        ),
        // 占位层
        Positioned(
          left: 60,
          top: 230,
          right: 60,
          height: 60,
          child: GestureDetector(
            onTap: () {
              _controller.reset();
              _controller.forward();
            },
            child: ImageFilterWidget(0.5),
          ),
        ),
        Positioned(
          left: 60 - 40 * _controller.value,
          top: 230 - 100 * _controller.value,
          right: 60 - 40 * _controller.value,
          height: 60 + 10 * _controller.value,
          child: GestureDetector(
            onTap: () {
              _controller.reset();
              _controller.forward();
            },
            child: ImageFilterWidget(0.5 - 0.5 * _controller.value),
          ),
        ),
      ]),
    );
  }
}
